home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 18.8 KB | 422 lines | [TEXT/CCL2] |
- (in-package :oou)
- (oou-provide :GWorld-svm)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; GWorld-svm.lisp
- ;;
- ;; Copyright © 1992 Northwestern University Institute for the Learning Sciences
- ;; All Rights Reserved
- ;;
- ;; author: Michael S. Engber
- ;; Tamar Offer
- ;;
- ;; mixin for using GWorlds to draw views
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (oou-dependencies :simple-view-ce
- :GWorld-view
- :QD-fx-u)
-
- (export '(GWorld-svm
- GWorld-view
- GW-current-slide GWorld-set-current-slide GWorld-draw-to-slide
- GWorld-slide-to-slide-copy GWorld-screen-to-slide-copy
- GWorld-margins GWorld-slide-size
- GW-copy-mode GW-copy-rgn GW-fore-color GW-back-color
- GW-update-fx GW-slide-fx GW-fx-delay GW-wipe-count
- GW-num-slides
- ))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- (defclass GWorld-svm ()
- ((GWorld-view :accessor GWorld-view
- :initarg :GWorld-view)
- (GW-init-fn :initarg :GW-init-fn
- :accessor GW-init-fn)
- (GW-num-slides :initarg :GW-num-slides
- :accessor GW-num-slides)
- (GW-current-slide :initarg :GW-current-slide
- :accessor GW-current-slide)
-
- (GW-copy-mode :initarg :GW-copy-mode
- :accessor GW-copy-mode)
- (GW-copy-rgn :initarg :GW-copy-rgn
- :accessor GW-copy-rgn)
- (GW-fore-color :initarg :GW-fore-color
- :accessor GW-fore-color)
- (GW-back-color :initarg :GW-back-color
- :accessor GW-back-color)
-
- (GW-update-fx :initarg :GW-update-fx
- :accessor GW-update-fx)
- (GW-slide-fx :initarg :GW-slide-fx
- :accessor GW-slide-fx)
- (GW-fx-delay :initarg :GW-fx-delay
- :accessor GW-fx-delay)
- (GW-wipe-count :initarg :GW-wipe-count
- :accessor GW-wipe-count)
- (GW-free-on-remove-p :initarg :GW-free-on-remove-p
- :accessor GW-free-on-remove-p)
- )
-
- (:default-initargs
- :GW-num-slides 1
- :GW-current-slide 0
- :GW-depth 8
-
- :GW-copy-mode #$srcCopy
- :GW-copy-rgn (%null-ptr)
- :GW-fore-color *black-color*
- :GW-back-color *white-color*
-
- :GW-update-fx :none
- :GW-slide-fx :transporter
- :GW-fx-delay 0
- :GW-wipe-count 8
- :GW-free-on-remove-p t
- ))
-
- (defmethod initialize-instance :after ((sv GWorld-svm) &rest initargs &key &allow-other-keys)
- (declare (dynamic-extent initargs))
- (unless (slot-boundp sv 'GWorld-view)
- (setf (GWorld-view sv) (apply #'make-instance 'GWorld-view
- :view-size (GWorld-total-slide-size sv)
- :view-position (GWorld-corners sv)
- :allow-other-keys t
- initargs))))
-
- (defmethod install-view-in-window :after ((sv GWorld-svm) w)
- (declare (ignore w))
- (GWorld-alloc (GWorld-view sv))
- (let ((install-complete nil))
- (unwind-protect
- (progn
- (GWorld-init-slides sv)
- (setf install-complete t))
- (unless install-complete
- (when (GW-free-on-remove-p sv)
- (GWorld-free (GWorld-view sv)))))))
-
- (defmethod remove-view-from-window :after ((sv GWorld-svm))
- (when (GW-free-on-remove-p sv)
- (GWorld-free (GWorld-view sv))))
-
- (defmethod view-draw-contents ((sv GWorld-svm))
- (GWorld-show-current-slide sv (GW-update-fx sv)))
-
- (defmethod set-view-size :after ((sv GWorld-svm) h &optional v)
- (declare (ignore h v))
- (set-view-size (GWorld-view sv) (GWorld-total-slide-size sv))
- (GWorld-update sv)
- (erase-view sv))
-
- (defmethod (setf GW-num-slides) :after (num-slides (sv GWorld-svm))
- (declare (ignore num-slides))
- (set-view-size (GWorld-view sv) (GWorld-total-slide-size sv))
- (GWorld-update sv))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (eval-when (:compile-toplevel :load-toplevel :execute)
-
- (defmacro with-GW-slide ((sv slide-num) &body body)
- (let ((cur-origin (gensym)))
- `(let ((,cur-origin (view-origin (GWorld-view ,sv))))
- (GWorld-set-origin (GWorld-view ,sv) (GWorld-slide-origin ,sv ,slide-num))
- (unwind-protect
- (progn ,@body)
- (GWorld-set-origin (GWorld-view ,sv) ,cur-origin)))))
-
- (defmacro with-locked-GW-slide ((sv slide-num) &body body)
- `(with-GW-slide (,sv ,slide-num)
- (with-locked-GWorld-view (GWorld-view ,sv)
- ,@body)))
-
- (defmacro with-focused-GW-slide ((sv slide-num) &body body)
- `(with-GW-slide (,sv ,slide-num)
- (with-focused-view (GWorld-view ,sv)
- ,@body)))
-
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-
- (defmethod GWorld-margins ((sv GWorld-svm))
- (declare (ignore sv))
- (values #@(0 0) #@(0 0)))
-
- (defmethod GWorld-corners ((sv GWorld-svm))
- (multiple-value-bind (topLeft botRight) (focused-corners sv)
- (multiple-value-bind (tl-margin br-margin) (GWorld-margins sv)
- (values (add-points topLeft tl-margin) (subtract-points botRight br-margin)))))
-
- (defmethod GWorld-slide-size ((sv GWorld-svm))
- (multiple-value-bind (topLeft botRight) (GWorld-corners sv)
- (subtract-points botRight topLeft)))
-
- (defmethod GWorld-total-slide-size ((sv GWorld-svm))
- (let ((slide-size (GWorld-slide-size sv)))
- (make-point (point-h slide-size)
- (* (GW-num-slides sv) (point-v slide-size)))))
-
- (defmethod GWorld-init-slides ((sv GWorld-svm))
- (when (slot-boundp sv 'GW-init-fn)
- (dotimes (i (GW-num-slides sv))
- (GWorld-draw-to-slide sv i (GW-init-fn sv)))))
-
- (defmethod GWorld-update ((sv GWorld-svm))
- (GWorld-realloc (GWorld-view sv))
- (GWorld-init-slides sv)
- (invalidate-view sv nil))
-
- ;;Returns the GWorld origin to use to put the topLeft of the slide at #@(0 0)
- (defmethod GWorld-slide-origin ((sv GWorld-svm) slide-num)
- (make-point 0 (* -1 slide-num (point-v (GWorld-slide-size sv)))))
-
-
- (defmethod GWorld-set-current-slide ((sv GWorld-svm) slide-num &key (inval-p nil) (draw-now-p t))
- (when slide-num
- (unless (and (>= slide-num 0) (< slide-num (GW-num-slides sv)))
- (error "slide number, ~a, out of bounds [~a-~a]." slide-num 0 (GW-num-slides sv))))
- (setf (GW-current-slide sv) slide-num)
- (when inval-p (invalidate-view sv (not slide-num)))
- (when draw-now-p
- (with-focused-view (focusing-view sv)
- (if slide-num
- (GWorld-show-current-slide sv (GW-slide-fx sv))
- (multiple-value-bind (topLeft botRight) (GWorld-corners sv)
- (rlet ((r :Rect :topLeft topLeft :botRight botRight))
- (#_EraseRect r)))))))
-
-
- (defmethod GWorld-draw-to-slide ((sv GWorld-svm) slide-num draw-fn)
- (with-focused-GW-slide (sv slide-num)
- (funcall draw-fn sv slide-num (GWorld (GWorld-view sv)))))
-
-
- (defmethod GWorld-slide-to-slide-copy ((sv GWorld-svm) from-slide-num to-slide-num
- &key
- (from-rect nil)
- (to-rect nil)
- (copy-mode #$srcCopy)
- (copy-rgn (%null-ptr))
- (fore-color *black-color*)
- (back-color *white-color*))
- (rlet ((f-rect :Rect
- :topLeft (if from-rect (pref from-rect :Rect.topLeft) #@(0 0))
- :botRight (if from-rect (pref from-rect :Rect.botRight) (GWorld-slide-size sv)))
- (t-rect :Rect
- :topLeft (if to-rect (pref to-rect :Rect.topLeft) #@(0 0))
- :botRight (if to-rect (pref to-rect :Rect.botRight) (GWorld-slide-size sv))))
- (#_OffsetRect :pointer f-rect :long (subtract-points (GWorld-slide-origin sv to-slide-num)
- (GWorld-slide-origin sv from-slide-num)))
- (with-focused-GW-slide (sv to-slide-num)
- (with-fore-color fore-color
- (with-back-color back-color
- (#_CopyBits (view-portBits (GWorld-view sv)) (view-portBits (GWorld-view sv)) f-rect t-rect copy-mode copy-rgn))))))
-
-
- (defmethod GWorld-screen-to-slide-copy ((sv GWorld-svm) slide-num
- &key
- (from-rect nil)
- (to-rect nil)
- (copy-mode #$srcCopy)
- (copy-rgn (%null-ptr))
- (fore-color *black-color*)
- (back-color *white-color*))
- (multiple-value-bind (topLeft botRight) (GWorld-corners sv)
- (rlet ((f-rect :Rect
- :topLeft (if from-rect (pref from-rect :Rect.topLeft) topLeft)
- :botRight (if from-rect (pref from-rect :Rect.botRight) botRight))
- (t-rect :Rect
- :topLeft (if to-rect (pref to-rect :Rect.topLeft) #@(0 0))
- :botRight (if to-rect (pref to-rect :Rect.botRight) (GWorld-slide-size sv))))
- (with-focused-view (focusing-view sv)
- (with-focused-GW-slide (sv slide-num)
- (with-fore-color fore-color
- (with-back-color back-color
- (#_CopyBits (view-portBits sv) (view-portBits (GWorld-view sv)) f-rect t-rect copy-mode copy-rgn))))))))
-
-
- ;;copies the specified slide on screen using the specified effect
- ;;Note: assumes it's already focused on the proper view
- (defmethod GWorld-show-current-slide ((sv GWorld-svm) fx-key)
- (when (GW-current-slide sv)
- (multiple-value-bind (topLeft botRight) (GWorld-corners sv)
- (rlet ((win-rect :Rect :topLeft topLeft :botRight botRight)
- (gw-rect :Rect :topLeft #@(0 0) :botRight (GWorld-slide-size sv)))
- (with-fore-color (GW-fore-color sv)
- (with-back-color (GW-back-color sv)
- (with-locked-GW-slide (sv (GW-current-slide sv))
- (with-macptrs ((gw-portBits (view-portBits (GWorld-view sv))))
- (ecase fx-key
- (:none (with-current-portBits win-portBits
- (#_CopyBits gw-portBits win-portBits gw-rect win-rect (GW-copy-mode sv) (GW-copy-rgn sv))))
- ((:transporter :waynes-world :screen-door :v-blind :h-blind)
- (dissolve-o-rama gw-portBits gw-rect win-rect
- :copy-mode (GW-copy-mode sv)
- :copy-rgn (GW-copy-rgn sv)
- :delay-ticks (GW-fx-delay sv)
- :dissolve-type fx-key))
- ((:left-to-right :right-to-left :top-to-bottom :bottom-to-top)
- (wipe-o-rama gw-portBits gw-rect win-rect
- :copy-mode (GW-copy-mode sv)
- :copy-rgn (GW-copy-rgn sv)
- :delay-ticks (GW-fx-delay sv)
- :wipe-count (GW-wipe-count sv)
- :wipe-direction fx-key))
- ((:round-iris-in :round-iris-out)
- (iris-o-rama gw-portBits gw-rect win-rect
- :copy-mode (GW-copy-mode sv)
- :copy-rgn (GW-copy-rgn sv)
- :delay-ticks (GW-fx-delay sv)
- :iris-direction (ecase fx-key
- (:round-iris-out :outward)
- (:round-iris-in :inward))
- :iris-shape :round))
- ((:square-iris-in :square-iris-out)
- (iris-o-rama gw-portBits gw-rect win-rect
- :copy-mode (GW-copy-mode sv)
- :copy-rgn (GW-copy-rgn sv)
- :delay-ticks (GW-fx-delay sv)
- :iris-direction (ecase fx-key
- (:square-iris-out :outward)
- (:square-iris-in :inward))
- :iris-shape :square))
- )))))))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- #|
-
- (oou-dependencies :PICT-u
- :back-PICT)
-
- (defclass off-screen-view (GWorld-svm view) ())
- (defvar *test-w*)
- (defparameter *xport-coordinates* #@(198 144))
- (defparameter *xport-dimensions* #@(59 182))
-
- (defun off-init (sv frame-num gw)
- (declare (ignore gw))
- (case frame-num
- (0
- (rlet ((r :Rect :topLeft (subtract-points #@(0 0) *xport-coordinates*)))
- (with-back-color (make-color -1 0 -1) (#_EraseRect r))
- (draw-picture-from-file "oou:examples;columns.PICT" r nil)
- ))
- (1
- (rlet ((r :Rect :topLeft #@(0 0) :botRight (GWorld-slide-size sv)))
- (with-back-color (make-color -1 0 -1) (#_EraseRect r))
- (draw-picture-from-file "oou:examples;kirk.PICT" r nil)))))
-
- (defun beam (in-p)
- (GWorld-set-current-slide (view-named :off *test-w*) (if in-p 1 0)))
-
- (defun off-fx (fx)
- (setf (GW-slide-fx (view-named :off *test-w*)) fx))
-
- (defun delay-set (ticks)
- (setf (GW-fx-delay (view-named :off *test-w*)) ticks))
-
- ;view this window on a color monitor
- (setf *test-w*
- (make-instance
- 'back-PICT-window
- :window-type :document
- :window-title "Transporter Demo"
- :color-p t
- :view-size #@(465 400)
- :PICT-file "oou:examples;columns.PICT"
- :PICT-scaling :adjust-view-size
- :PICT-storage :disk
- :view-subviews
- (list (make-instance 'off-screen-view
- :view-position *xport-coordinates*
- :view-size *xport-dimensions*
- :view-nick-name :off
- :GW-depth 8
- :GW-num-slides 2
- :GW-current-slide 0
- :GW-back-color (make-color #xFFFF 0 #xFFFF)
- :GW-copy-mode (+ #$patCopy #$transparent)
- :GW-init-fn 'off-init)
- (make-instance 'button-dialog-item
- :dialog-item-text "Beam me down"
- :view-font '("Geneva" 0)
- :view-position #@(5 5)
- :dialog-item-action #'(lambda (di) (declare (ignore di)) (beam t)))
- (make-instance 'button-dialog-item
- :dialog-item-text "Beam me up"
- :view-font '("Geneva" 0)
- :view-position #@(110 5)
- :dialog-item-action #'(lambda (di) (declare (ignore di)) (beam nil)))
- (make-instance 'pop-up-menu
- :dialog-item-text ""
- :view-position #@(200 5)
- :view-size #@(120 20)
- :menu-items (list (make-instance 'menu-item
- :menu-item-title "transporter"
- :menu-item-action #'(lambda () (off-fx :transporter)))
- (make-instance 'menu-item
- :menu-item-title "Wayne's World"
- :menu-item-action #'(lambda () (off-fx :waynes-world)))
- (make-instance 'menu-item
- :menu-item-title "screen door"
- :menu-item-action #'(lambda () (off-fx :screen-door)))
- (make-instance 'menu-item
- :menu-item-title "h-blind"
- :menu-item-action #'(lambda () (off-fx :h-blind)))
- (make-instance 'menu-item
- :menu-item-title "v-blind"
- :menu-item-action #'(lambda () (off-fx :v-blind)))
- (make-instance 'menu-item
- :menu-item-title "l-to-r"
- :menu-item-action #'(lambda () (off-fx :left-to-right)))
- (make-instance 'menu-item
- :menu-item-title "r-to-l"
- :menu-item-action #'(lambda () (off-fx :right-to-left)))
- (make-instance 'menu-item
- :menu-item-title "t-to-b"
- :menu-item-action #'(lambda () (off-fx :top-to-bottom)))
- (make-instance 'menu-item
- :menu-item-title "b-to-t"
- :menu-item-action #'(lambda () (off-fx :bottom-to-top)))
- (make-instance 'menu-item
- :menu-item-title "round iris out"
- :menu-item-action #'(lambda () (off-fx :round-iris-out)))
- (make-instance 'menu-item
- :menu-item-title "round iris in"
- :menu-item-action #'(lambda () (off-fx :round-iris-in)))
- (make-instance 'menu-item
- :menu-item-title "square iris in"
- :menu-item-action #'(lambda () (off-fx :square-iris-in)))
- (make-instance 'menu-item
- :menu-item-title "square iris out"
- :menu-item-action #'(lambda () (off-fx :square-iris-out)))
- (make-instance 'menu-item
- :menu-item-title "none"
- :menu-item-action #'(lambda () (off-fx :none)))
- ))
- (make-instance 'pop-up-menu
- :view-position #@(325 5)
- :view-size #@(120 20)
- :dialog-item-text ""
- :menu-items (list (make-instance 'menu-item
- :menu-item-title "no delay"
- :menu-item-action #'(lambda () (delay-set 0)))
- (make-instance 'menu-item
- :menu-item-title "2 ticks"
- :menu-item-action #'(lambda () (delay-set 2)))
- (make-instance 'menu-item
- :menu-item-title "5 ticks"
- :menu-item-action #'(lambda () (delay-set 5)))
- (make-instance 'menu-item
- :menu-item-title "10 ticks"
- :menu-item-action #'(lambda () (delay-set 10)))))
- )))
-
-
- |#